package edu.univercidade.tcc.sap.client.controller;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.VerticalPanel;

import edu.univercidade.tcc.sap.client.Messages;
import edu.univercidade.tcc.sap.client.widget.MenuTable;

public abstract class TableMenuCommand implements Command {

	protected Panel renderPanel;

	protected abstract MenuTable table();

	private final Messages messages = GWT.create(Messages.class);

	public TableMenuCommand(Panel renderPanel) {
		this.renderPanel = renderPanel;
	}

	@Override
	public void execute() {
		VerticalPanel panel = new VerticalPanel();
		
		MenuTable userTable = table();
		
		Button newButton = new Button(messages.newButton());
		newButton.addClickHandler(userTable.newHandler());
		
		Button updateButton = new Button(messages.updateButton());		
		updateButton.addClickHandler(userTable.updateHandler());
		
		Button resetButton = new Button(messages.resetButton());
		resetButton.addClickHandler(userTable.resetHandler());
		
		panel.add(userTable);
		
		Panel buttonPanel = new HorizontalPanel();
		buttonPanel.add(newButton);
		buttonPanel.add(updateButton);
		buttonPanel.add(resetButton);
		panel.add(buttonPanel);
		
		renderPanel.clear();
		renderPanel.add(panel);
	}

}